package com.caiden_micheal.permission.web;

import com.caiden_micheal.base.aop.annotation.PermissionVerify;
import com.caiden_micheal.base.domain.AjxResult;
import com.caiden_micheal.permission.domain.Permission;
import com.caiden_micheal.permission.dto.FindPermissionSelectData;
import com.caiden_micheal.permission.service.PermissionService;
import com.caiden_micheal.permission.vo.PermissionQueryVO;
import com.caiden_micheal.permission.vo.PermissionRemoveVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    @PermissionVerify(permissionArray = {"sys:userManagement:permissionView", "sys:orgManagement:viewPermission", "sys:positionManagement:viewPermission"})
    @PostMapping("/permissionQuery")
    public AjxResult permissionInfoPageQuery(@RequestBody PermissionQueryVO permissionQueryVO) {
        return AjxResult.success(permissionService.findPermissionsByCondition(permissionQueryVO));
    }

    @PermissionVerify(permissionArray = {"sys:permissionManagement"})
    @PostMapping("/permissionQueryWithMenuId")
    public AjxResult permissionQueryWithMenuId(@RequestBody PermissionQueryVO permissionQueryVO) {
        return AjxResult.success(permissionService.findPermissionsByConditionMenu(permissionQueryVO));
    }

    @PermissionVerify(permissionArray = {"sys:positionManagement:assignPermission"})
    @PostMapping("/permissionQueryExcludePositionId")
    public AjxResult permissionQueryExcludePositionId(@RequestBody PermissionQueryVO permissionQueryVO) {
        return AjxResult.success(permissionService.findPermissionsByConditionExcludePositionId(permissionQueryVO));
    }

    @PermissionVerify(permissionArray = {"sys:orgManagement:assignPermission"})
    @PostMapping("/permissionQueryExcludeOrgId")
    public AjxResult permissionQueryExcludeOrgId(@RequestBody PermissionQueryVO permissionQueryVO) {
        return AjxResult.success(permissionService.findPermissionsByConditionExcludeOrgId(permissionQueryVO));
    }

    @PermissionVerify(permissionArray = {"sys:userManagement:assignPermission"})
    @PostMapping("/permissionQueryExcludeUserId")
    public AjxResult permissionQueryExcludeUserId(@RequestBody PermissionQueryVO permissionQueryVO) {
        return AjxResult.success(permissionService.permissionQueryExcludeUserId(permissionQueryVO));
    }

    /*
    过时方法
    @PostMapping("/addPermission")
    public AjxResult addPermission(@RequestBody Permission permission) {
        return permissionService.addPermission(permission);
    }*/
    @PermissionVerify(permissionArray = {"sys:permissionManagement:add"})
    @PostMapping("/addPermissionWithMenuId")
    public AjxResult addPermissionWithMenuId(@RequestBody Permission permission) {
        return permissionService.addPermissionWithMenuId(permission);
    }

    @PermissionVerify(permissionArray = {"sys:permissionManagement:edit"})
    @PostMapping("/editPermission")
    public AjxResult editPermission(@RequestBody Permission permission) {
        return permissionService.editPermission(permission);
    }

    @PermissionVerify(permissionArray = {"sys:permissionManagement:delete"})
    @PostMapping("/removePermission")
    public AjxResult removePermission(@RequestBody PermissionRemoveVO permissionRemoveVO) {
        return permissionService.removePermission(permissionRemoveVO.getId());
    }

    @PostMapping("/findPermissionSelectData")
    public AjxResult findPermissionSelectData(@RequestBody FindPermissionSelectData findPermissionSelectData) {
        return permissionService.findPermissionSelectData(findPermissionSelectData);
    }
}
